#include "qprojecthost.h"

#include "qabstractproperty.h"
#include "qpropertyfactory.h"
#include "qusermanager.h"
#include "qlanguagemanager.h"
#include "qpagemanager.h"
#include "qprojectresource.h"
#include "qprojectcore.h"
#include "qmemerymanager.h"
#include "qcommonstruct.h"

using namespace SHAREDLIB;

QProjectHost::QProjectHost(QObject *object):
    QAbstractHost(object)
{
    m_project=(QProjectCore*)object;
    initProperty();
}

void QProjectHost::initProperty()
{
    QAbstractProperty *pro;
    pro=QPropertyFactory::createProperty("ByteArray");
    if(pro!=NULL)
    {
        pro->setAttribute("name","objectName");
        pro->setAttribute("property_name",tr("Name"));
        pro->setAttribute("NeedSave",true);
        pro->setAttribute("group",tr("Project"));
        m_object->setProperty("objectName","");
        pro->setAttribute("editabled",false);
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("ByteArray");
    if(pro!=NULL)
    {
        pro->setAttribute("name","path");
        pro->setAttribute("property_name",tr("Path"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Project"));
        pro->setAttribute("editabled",false);
        m_object->setProperty("path","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Number");
    if(pro!=NULL)
    {
        pro->setAttribute("name","permission");
        pro->setAttribute("property_name",tr("Permission"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Project"));
        pro->setAttribute("min",0);
        pro->setAttribute("max",100);
        m_object->setProperty("permission",10);
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Size");
    if(pro!=NULL)
    {
        pro->setAttribute("name","desize_size");
        pro->setAttribute("property_name",tr("Desize Size"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));
        m_object->setProperty("desize_size",QSize(800,600));
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Size");
    if(pro!=NULL)
    {
        pro->setAttribute("name","size");
        pro->setAttribute("property_name",tr("Running Size"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));
        m_object->setProperty("size",QSize(800,600));
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Bool");
    if(pro!=NULL)
    {
        pro->setAttribute("name","resizeabled");
        pro->setAttribute("property_name",tr("Resizeable"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));
        m_object->setProperty("resizeabled",false);
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Bool");
    if(pro!=NULL)
    {
        pro->setAttribute("name","fullscreen");
        pro->setAttribute("property_name",tr("Full Screen"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));
        m_object->setProperty("fullscreen",false);
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Enum");
    if(pro!=NULL)
    {
        pro->setAttribute("name","showtype");
        pro->setAttribute("property_name",tr("Show Type"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));

        ComboItems items;
        tagComboItem item;

        item.m_text=tr("Fit size");
        item.m_value=0;
        items.append(item);

        item.m_text=tr("Original size");
        item.m_value=1;
        items.append(item);

        QVariant v;
        v.setValue<ComboItems>(items);
        pro->setAttribute("items",v);
        m_object->setProperty("showtype",0);

        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Bool");
    if(pro!=NULL)
    {
        pro->setAttribute("name","frame");
        pro->setAttribute("property_name",tr("Frame"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));
        m_object->setProperty("frame",false);
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Enum");
    if(pro!=NULL)
    {
        pro->setAttribute("name","start_page");
        pro->setAttribute("property_name",tr("Page"));
        pro->setAttribute("NeedSave",true);
        pro->setAttribute("group",tr("Project"));
        m_object->setProperty("start_page","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Enum");
    if(pro!=NULL)
    {
        pro->setAttribute("name","start_language");
        pro->setAttribute("property_name",tr("Language"));
        pro->setAttribute("NeedSave",true);
        pro->setAttribute("group",tr("Project"));
        m_object->setProperty("start_language","");
        addProperty(pro);
    }


    pro=QPropertyFactory::createProperty("Enum");
    if(pro!=NULL)
    {
        pro->setAttribute("name","start_user");
        pro->setAttribute("property_name",tr("User"));
        pro->setAttribute("NeedSave",true);
        pro->setAttribute("group",tr("Project"));
        m_object->setProperty("start_user","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("String");
    if(pro!=NULL)
    {
        pro->setAttribute("name","windowTitle");
        pro->setAttribute("property_name",tr("Title"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Window"));
        m_object->setProperty("windowTitle","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","befort_start");
        pro->setAttribute("property_name",tr("Befort start"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Event"));
        m_object->setProperty("befort_start","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","befort_close");
        pro->setAttribute("property_name",tr("Befort close"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Event"));
        m_object->setProperty("befort_close","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","userChanged");
        pro->setAttribute("property_name",tr("User Changed"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Event"));
        m_object->setProperty("userChanged","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","languageChanged");
        pro->setAttribute("property_name",tr("Language Changed"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Event"));
        m_object->setProperty("languageChanged","");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","dataChanged");
        pro->setAttribute("property_name",tr("Data Changed"));
        pro->setAttribute("NeedSave",false);
        pro->setAttribute("group",tr("Event"));
        m_object->setProperty("dataChanged","");
        addProperty(pro);
    }
}

void QProjectHost::setNew()
{
    clear();
    initProperty();
    m_project->m_userManager->release();
    m_project->m_languageManager->release();
    QProjectResource::release();
    m_project->m_pageManager->clear();
    m_project->m_memeryManager->clear();
}

bool QProjectHost::showPage(const QString &name)
{
    return false;
}

void QProjectHost::firstScript()
{

}

void QProjectHost::lastScript()
{

}
